<!--
 * @Description: 秒杀商品,商品数据
 * @Author: along
 * @Date: 2021-08-23
 * @Last Modified by: along
 * @Last Modified time: 2021-08-23
-->
<template>
    <div class="container seckillGoodsDate">
        <!-- title -->
        <div class="__title">
            <div class="__title_name">商品数据</div>
        </div>

        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">商品信息</p>
                    <el-input
                        v-model="formData.keyword"
                        placeholder="请输入商品名称/编号"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">店铺名称</p>
                    <el-input
                        v-model="formData.shop_title"
                        placeholder="请输入店铺名称"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: calc(100% - 64px); margin-left: 32px"
            border
            ref="seckillGoodsDate"
            @sort-change="handleSortChanged"
        >
            <el-table-column
                prop="goods_cover"
                label="商品信息"
                :formatter="emptyFormatter"
                align="left"
                :width="350"
            >
                <template slot-scope="scope">
                    <div class="__items">
                        <img
                            :src="scope.row.goods_cover"
                            class="__items_logo"
                        >
                        <div class="__items_info">
                            <p class="__items_title">{{ scope.row.goods_title }}</p>
                            <p class="__items_nos">商品编号: {{ scope.row.goods_no }}</p>
                            <p class="__items_name">店铺名称: {{ scope.row.shop_title }}</p>
                        </div>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="price"
                label="秒杀价"
                :formatter="emptyFormatter"
                align="left"
                :width="120"
            >
                <template slot-scope="scope">
                    <div class="__list">
                        <p>¥{{ scope.row.price }}起</p>
                        <p
                            class="__list_check"
                            @click="showPriceDialog(scope.row)"
                        >查看</p>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_price"
                label="学生价"
                :formatter="emptyFormatter"
                align="left"
                :width="120"
            >
                <template slot-scope="scope">
                    <div class="__list">
                        <p>¥{{ scope.row.goods_price }}起</p>
                        <p
                            class="__list_check"
                            @click="showPriceDialog(scope.row)"
                        >查看</p>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                label="佣金比例"
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <div class="__list">
                        <p
                            class="__list_check"
                            @click="showPriceDialog(scope.row)"
                            :style="{color: '#20a0ff', cursor: 'pointer'}"
                        >查看</p>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="stock"
                label="活动库存"
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <div class="__list">
                        <p>¥{{ scope.row.stock }}起</p>
                        <p
                            class="__list_check"
                            @click="showPriceDialog(scope.row)"
                        >查看</p>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="create_time"
                label="创建时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="total_show_sale_num"
                label="总销量"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable="custom"
                :width="110"
            />
            <el-table-column
                prop="total_view_count"
                label="真实浏览量"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable="custom"
                :width="120"
            />
            <el-table-column
                prop="total_show_view_count"
                label="企业主浏览量"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable="custom"
                :width="130"
            />
            <el-table-column
                prop="total_order_count"
                label="总订单数"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable="custom"
                :width="110"
            />
            <el-table-column
                prop="total_order_money"
                label="总金额"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable="custom"
                :width="100"
            />
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 查看价格弹窗 -->
        <el-dialog
            title="查看商品"
            :visible.sync="productVisible"
            width="800px"
            :close-on-click-modal="false"
        >
            <el-table
                :data="detailRow.product_list"
                height="100%"
                style="width: 100%;max-height: 450px"
                class="data-table"
            >
                <el-table-column
                    prop="spec_list"
                    label="规格名称"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.goods_specs | filterSpec }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="price"
                    label="秒杀价(元)"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="product_price"
                    label="学生价(元)"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="stock"
                    label="活动库存"
                    show-overflow-tooltip
                    align="left"
                />
                <el-table-column
                    prop="commission_rate"
                    label="佣金比例"
                    show-overflow-tooltip
                    align="left"
                />
            </el-table>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="productVisible = false"
                    size="medium"
                    type="primary"
                >
                    我知道了
                </el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {back} from '@/mixin/back';
export default {
    mixins: [back],
    components: {},
    data() {
        return {
            detailRow: {},
            productVisible: false,
            formData: {
                keyword: '',
                shop_title: ''
            },
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            filterData: {
                sort_field: 0,
                sort_type: 1
            },
            authResult: {}
        };
    },
    computed: {},
    watch: {},
    filters: {
        filterSpec (val) {
            if(!val) return '';
            let str = '';

            val.forEach(el => {
                str += el.spec_name + ':' + el.spec_value + ';';
            });
            return str;
        }
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: '活动管理'}, {title: '限时秒杀'}, {title: '商品数据'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/shop_goods_flash_sale_activity%5Cget_goods_statistic_list', {
                page_id: page || this.page.now_page,
                sort_field: this.filterData.sort_field,
                sort_type: this.filterData.sort_type,
                keyword: this.formData.keyword,
                shop_title: this.formData.shop_title
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * 显示详细价格弹窗
         * @param row
         */
        showPriceDialog(row) {
            this.productVisible = true;
            this.detailRow = row;
        },

        /**
         * @description 数据排序
         */
        handleSortChanged(data) {
            let sortTypeMap = {
                ascending: 0,
                descending: 1
            };

            let sortFieldMap = {
                total_show_sale_num: 'total_show_sale_num',
                total_view_count: 'total_view_count',
                total_show_view_count: 'total_show_view_count',
                total_order_count: 'total_order_count',
                total_order_money: 'total_order_money'
            };

            if (data.order) {
                this.filterData.sort_field = sortFieldMap[data.prop];
                this.filterData.sort_type = sortTypeMap[data.order];
            } else {
                this.filterData.sort_field = '';
                this.filterData.sort_type = '';
            }

            this.getTableData();
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
.seckillGoodsDate {
    background-color: #fff;
    display: flex;
    flex-direction: column;
    position: relative;
    box-sizing: border-box;
    margin: 12px;
    overflow: hidden;
    .__title {
        width: 100%;
        height: 78px;
        display: flex;
        align-items: center;
        box-sizing: border-box;
        padding-left: 35px;
        border-bottom: 1px rgba(240, 242, 245, 1) solid;
        .__title_name {
            color: #333;
            font-size: 20px;
            font-weight: 500;
            position: relative;
            &::before {
                content: '';
                position: absolute;
                top: 0;
                left: -8px;
                width: 3px;
                height: 20px;
                background: rgba(24, 144, 255, 1);
            }
        }
    }
    .header-nav {
        position: relative;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        margin-left: 32px;
        .header-left, .header-right {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
        }
        .header-new-box {
            display: flex;
            margin-right: 15px;
            align-items: center;
            color: #606266;
            white-space: nowrap;
            margin-top: 24px;
            margin-bottom: 24px;
            &-title {
                margin-right: 12px;
                white-space: nowrap;
            }
        }
    }

    .__items {
        display: flex;
        align-items: center;
        margin: 12px 0;
        .__items_logo {
            width: 108px;
            height: 108px;
            margin-right: 16px;
        }
        .__items_info {
            display: flex;
            flex-direction: column;
            height: 108px;
            justify-content: space-between;
            .__items_title {
                color: rgba(51, 51, 51, 1);
                font-size: 14px;
                line-height: 20px;
                width: 186px;
                overflow : hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
            }
            .__items_nos {
                width: 186px;
                color: rgba(51, 51, 51, 1);
                font-size: 12px;
                white-space: nowrap;
            }
            .__items_name {
                width: 186px;
                color: rgba(51, 51, 51, 1);
                font-size: 12px;
                white-space: nowrap;
            }
        }
    }

    .__list {
        display: flex;
        align-items: center;
        p {
            white-space: nowrap;
        }
        .__list_check {
            color: rgba(32, 160, 255, 1);
            font-size: 14px;
            margin-left: 5px;
            cursor: pointer;
            white-space: nowrap;
            &:hover {
                text-decoration: underline;
            }
        }
    }
    /* 表单 */
    .scope-price {
        width: 50px;
        height: 50px;
    }
    /* 字体高亮 */
    .cursor-font {
        color: rgb(64, 158, 255);
        cursor: pointer;
    }
    /* 分页 */
    .pagination-wrapper {
        padding-top: 10px;
        padding-bottom: 10px;
        display: flex;
        justify-content: flex-end;
        .el-pagination {
            float: right;
            padding: 0;
            background-color: transparent;
        }
    }
}
/* 排序 */
.sort-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    .sort-spliter {
        width: 1px;
        height: 12px;
        background: rgba(235, 235, 235, 1);
        margin: 0 10px;
        }
        .btn-sort {
        font-size: 14px;
        line-height: 1;
        color: #ccc;
        &:hover {
            color: #20a0ff;
        }
    }
}
.el-button-left {
    margin-left: 40px;
}
.el-button-right {
    margin-right: 10px;
}
</style>

<style lang="less">
.seckillGoodsDate{
    .el-table__body-wrapper .el-table__body .el-table__row td {
        border-right: none;
    }
    .el-table__header-wrapper .el-table__header .has-gutter tr th {
        border-right: none;
    }
    .el-table .el-table_1_column_6  .cell {
        position: relative;
    }
    .el-range-editor--small .el-range-separator{
        padding: 0 1px !important;
    }
}
</style>
